package common.degrafa.render
{
	import com.degrafa.Surface;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.controls.Alert;

	public class ShowMap  extends EventDispatcher
	{
		public var gdSvgMap : WinPanel = new WinPanel();
		
		public function showMap() : void{
			var request: URLRequest=new URLRequest("asset/svg/p_gd.svg");			
			var loaderSVG: URLLoader=new URLLoader(request);			
			loaderSVG.addEventListener(Event.COMPLETE, procesarSVG);	
			loaderSVG.addEventListener(IOErrorEvent.IO_ERROR, errorOnChargeFile);
		}
		
		private function procesarSVG(e: Event): void{		
			
			var xmlSVG: XML = new XML(e.target.data);	
			var dibujador:SVGToGeometry=new SVGToGeometry();
			var surface:Surface= dibujador.cargar(xmlSVG);
			//var gdSvgMap : Window = new Window();
			gdSvgMap.width = 480;
			gdSvgMap.x = 300;
			gdSvgMap.y = 100;
			gdSvgMap.height = 360;
			gdSvgMap.id = "gdSvgMap";
			gdSvgMap.doubleClickEnabled = true;
			gdSvgMap.addEventListener(MouseEvent.MOUSE_DOWN , function(event: MouseEvent) : void{
				dispatchEvent(event);
			});
			gdSvgMap.title = "广东地图";
			//gdSvgMap.draggable = true;
			//gdSvgMap.showCloseButton = true;
			//gdSvgMap.showMaximizeButton = true;
			gdSvgMap.allowClose = true;
			gdSvgMap.allowDrag = true;
			gdSvgMap.allowMaximize = true;
			gdSvgMap.allowMinimize = true;
			gdSvgMap.allowResize = true;
			gdSvgMap.addChild(surface);
		}
		
		private function errorOnChargeFile(e: IOErrorEvent):void{
			Alert.show("error al cargar el archivo");
			trace(e.text);
		}
	}
}